#include"BlockQueue.hpp"
#include<unistd.h>

struct ThreadData
{
    BlockQueue<int> *bq;
    std::string name;
};

void* consumer(void* args)
{
    // std::string name = static_cast<char*>(args);
    ThreadData * td = static_cast<ThreadData*>(args);
    while(true)
    {
        int t;
        td->bq->Pop(&t);
        std::cout<<"消费者消费了："<<t<<std::endl;
    }
}

void* productor(void* args)
{
    ThreadData* td = static_cast<ThreadData*>(args);
    int data = 1;
    while(true)
    {
        td->bq->Enqueue(data);
        std::cout<<"生产者生产:"<<data++<<std::endl;
    }
}

void test1()
{
    BlockQueue<int>* bp = new BlockQueue<int>();
    ThreadData ctd = {bp,"消费者"};
    pthread_t c , p;
    pthread_create(&c , nullptr , consumer,(void*)&ctd);

    ThreadData ptd = {bp , "生产者"};
    pthread_create(&p,nullptr , productor , (void*)&ptd);

    pthread_join(c, nullptr);
    pthread_join(p, nullptr);
}

int main()
{
    test1();
    return 0;
}